const { defineConfig } = require('@vue/cli-service')
let {list}=require('./src/mock')
const bodyParser=require('body-parser')
module.exports = defineConfig({
  transpileDependencies: true,
  devServer:{
    setupMiddlewares(middlewares,{app}){
      app.use(bodyParser.json())
      app.get('/api/list',(req,res)=>{
        const {page=1,pageSize=10}=req.query
        res.send({
          list:list.slice((page-1)*pageSize,page*pageSize),
          length:list.length
        })
      })
      app.post('/api/list/main',(req,res)=>{
        const data=[0,0,0,0,0,0]
        list.forEach(v=>{
          if(v.age>=18&&v.age<25){
            data[0]++
          }else if(v.age>=25&&v.age<32){
            data[1]++
          }else if(v.age>=32&&v.age<39){
            data[2]++
          }else if(v.age>=39&&v.age<46){
            data[3]++
          }else if(v.age>=46&&v.age<53){
            data[4]++
          }else if(v.age>=53&&v.age<=60){
            data[5]++
          }
        })
        res.send({
          data
        })
      })
      app.get('/api/list/delte',(req,res)=>{
        const {id}=req.query
        list=list.filter(v=>v.id!==id)
        res.send({
          code:200,
          message:'删除成功'
        })
      })
      return middlewares
    }
  }
})
